package com.example.gulimall.order.controller.web;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.example.gulimall.order.entity.OrderEntity;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Controller
public class controller {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("/{page}.html")
    public  String listPage(@PathVariable("page") String page){
        return  page;
    }
    @ResponseBody
    @GetMapping("/test/createOrder")
    public String createOrder(){
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setOrderSn(UUID.randomUUID().toString());
        orderEntity.setModifyTime(new Date());
        //给mq发送消息
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity);
        return "ok";
    }

//    @NacosInjected
//    NamingService namingService;
//    @GetMapping("/getByServerName")
//    public void getService() throws NacosException {
//        List<Instance> allInstances = namingService.getAllInstances("gulimall-order");
//        allInstances.forEach(all->{
//            System.err.println(all.getIp());    //ip
//            System.err.println(all.getPort());  //端口
//        });
//        System.out.println(allInstances);
//    }
}
